package com.bst.web.etl;

import com.bst.common.core.controller.BaseController;
import com.bst.common.core.domain.AjaxResult;
import com.bst.common.vo.HeaderAndBodyVO;
import com.bst.etl.service.IEtlQryDmPubChartService;
import com.bst.etl.service.IEtlQryDmPubService;
import com.bst.etl.service.IEtlQryDwPubService;
import com.bst.etl.vo.chart.ChartParamVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/base/etl/chart")
public class EtlChartController extends BaseController {

    @Autowired
    IEtlQryDmPubService etlDmQueryService;
    @Autowired
    IEtlQryDmPubChartService etlQryDmPubChartService;
    @Autowired
    IEtlQryDwPubService etlQryDwPubService;

    @ApiOperation(value="基础图表查询")
    @RequestMapping(value="/dmCommon", method= RequestMethod.POST)
    @ResponseBody
    public AjaxResult dmCommon(@RequestBody ChartParamVO shapeParamVO) {
        AjaxResult result = etlDmQueryService.findIndexDataWithHeader(shapeParamVO.getDmQueryParamVO());
        if(!AjaxResult.isSuccess(result)) {
            return result;
        }
        HeaderAndBodyVO headerAndBodyVO = (HeaderAndBodyVO)result.get("data");
        if(headerAndBodyVO==null) {
            return AjaxResult.success();
        }
        return etlQryDmPubChartService.generateBaseShape(headerAndBodyVO,shapeParamVO.getChartStyleVO());
    }

    @ApiOperation(value="基础图表查询")
    @RequestMapping(value="/dwCommon", method= RequestMethod.POST)
    @ResponseBody
    public AjaxResult dwCommon(@RequestBody ChartParamVO shapeParamVO) {
        AjaxResult result = etlQryDwPubService.findIndexDataWithHeader(shapeParamVO.getDwQueryParamVO());
        if(!AjaxResult.isSuccess(result)) {
            return result;
        }
        HeaderAndBodyVO headerAndBodyVO = (HeaderAndBodyVO)result.get("data");
        if(headerAndBodyVO==null) {
            return AjaxResult.success();
        }
        return etlQryDmPubChartService.generateBaseShape(headerAndBodyVO,shapeParamVO.getChartStyleVO());
    }
}
